package com.ruoyi.multab.domain;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONObject;

public class MulModelResult {
	
	private int ragaMaxAindex = 0;
	private Object ragaMaxAvalue = null;
	private Object doubleArrayB = null;
	private Object doubleArrayIndex = null;
	private Object doubleArrayFv1 = null;
	
	public int getRagaMaxAindex() {
		return ragaMaxAindex;
	}
	public void setRagaMaxAindex(int ragaMaxAindex) {
		this.ragaMaxAindex = ragaMaxAindex;
	}
	public Object getRagaMaxAvalue() {
		return ragaMaxAvalue;
	}
	public void setRagaMaxAvalue(Object ragaMaxAvalue) {
		this.ragaMaxAvalue = ragaMaxAvalue;
	}
	public Object getDoubleArrayB() {
		return doubleArrayB;
	}
	public void setDoubleArrayB(Object doubleArrayB) {
		//将二维数组转为字符串array
		double[][] obj = (double[][]) doubleArrayB;
		List<String> listFromArray = MulModelResult.getListFromArray(obj[0],4);
		List<JSONObject> dataArray = new ArrayList<JSONObject>();
		JSONObject jobj = new JSONObject();
		for(int i = 0;i<listFromArray.size();i++) {
			jobj.put("dataValue"+i, listFromArray.get(i));

		}
		dataArray.add(jobj);
		this.doubleArrayB = dataArray;
	}
	public Object getDoubleArrayIndex() {
		return doubleArrayIndex;
	}
	public void setDoubleArrayIndex(Object doubleArrayIndex) {
		double[][] obj = (double[][]) doubleArrayIndex;
		this.doubleArrayIndex = MulModelResult.getListFromArray(obj[0],0);
	}
	public Object getDoubleArrayFv1() {
		return doubleArrayFv1;
	}
	public void setDoubleArrayFv1(Object doubleArrayFv1) {
		double[][] obj = (double[][]) doubleArrayFv1;
		this.doubleArrayFv1 = MulModelResult.getListFromArray(obj[0],4);
	}
	
	public static void main(String[] args) {
		double[][] obj = {{0.32368760763728066, 0.5245002116951896, 0.39941877507636275, 0.3759373345415777, 0.43733566580660216, 0.357769672584923}};
		double[] target = obj[0];
		List<String> result = getListFromArray(target,4);
		System.out.println(result);
		
//		BigDecimal bigDecimal = new BigDecimal(0.32368760763728066);
//		BigDecimal setScale = bigDecimal.setScale(4,BigDecimal.ROUND_HALF_UP);
//		String str = setScale.toString();
//		System.out.println(str);
	}
	/**
	 * 将数组转为字符串集合,按指定位数保留小数
	 * @param target 数组
	 * @param scale 小数位数
	 * @return
	 */
	private static List<String> getListFromArray(double[] target,int scale) {
		
		List<String> list = new ArrayList<String>();
		
		for(int i = 0;i<target.length;i++) {
			double value = target[i];
			BigDecimal bigDecimal = new BigDecimal(value);
			BigDecimal setScale = bigDecimal.setScale(scale,BigDecimal.ROUND_HALF_UP);
			String str = setScale.toString();
			list.add(str);
		}
		return list;
	}

}
